home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 41
/
Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso
/
Aminet
/
util
/
sys
/
InstallerNG.lha
/
InstallerNG
/
examples
/
descent.installer
next >
Wrap
Text File
|
2000-10-01
|
2KB
|
88 lines
; this needs the InstallerNG!
(if (not @installer-ng-version)
(abort "This script needs the InstallerNG by Jens Tröger")
)
; inform the user
(message "This example shows, how to recursively descent into a directory "
"tree and performing an action on every file or sub-directory.\n\n"
"Additionally this script demonstrates, how to append \".mp3\" to every filename, "
"which misses this postfix"
)
(swing
; ask for the root directory
(set #rootdir (askdir (prompt "Please select the root directory,\nfrom where the InstallerNG should descent!")
(help "")
(default "WORK:")
)
)
; ask for maximal supported filename length
(set #maxlen (asknumber (prompt "What is the maximal length of a filename,\nsupported by your filesystem?")
(help "")
(default 31)
)
)
; ask for confirmation to start
(message "Done?")
)
; now rename all the files!
(working "Now adding \".mp3\" to all the files...")
(P_renameDir #rootdir)
; and done with the job...
(exit (quiet))
(welcome)
; the procedure, which renames all files and descends recursively
; into the directories
(procedure P_renameDir #d
(debug (cat "DIRECTORY: " #d))
; create a new environment and walk through the directory
(let (set #dir #d)
(
(foreach #dir "#?" (
; for a file, call the file-handling procedure
(if (< @each-type 0) (P_renameFile #dir @each-name))
; descent into a sub-directory
(if (> @each-type 0) (P_renameDir (tackon #dir @each-name)))
)
)
)
)
)
; rename a file
(procedure P_renameFile #d #f
; create a new environment
(let (set #dir #d #file #f)
; is the end of this filename ".mp3" ??
(if (= ".mp3" (substr #file (- (strlen #file) 4)))
; yes
(debug (cat "\t" #file " ... skipped"))
; no - append the ".mp3" (respect the maximal length of a filename
; supported by the filesystem!
(
(rename (tackon #dir #file) (tackon #dir (cat (substr #file 0 (- #maxlen 4)) ".mp3")) (safe))
(debug (cat "\t" #file " ... renamed"))
)
)
)
)